package utn.frba.matematicasuperior.controladores;

import javafx.fxml.FXML;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.stage.Stage;
import utn.frba.matematicasuperior.main.Main;
import utn.frba.matematicasuperior.modelo.ParOrdenado;
import utn.frba.matematicasuperior.modelo.PolinomioInterpolante;
import utn.frba.matematicasuperior.utiles.Controlador;

public class GraficoControlador implements Controlador {

	/************************************************************/
	/************************ ATRIBUTOS *************************/
	/************************************************************/

	private Main main;
	private Stage escenario;
	private PolinomioInterpolante polinomio;

	@FXML
	private LineChart<Double, Double> lineChartGrafico;

	@FXML
	private NumberAxis ejeX;

	@FXML
	private NumberAxis ejeY;

	@FXML
	private Button btnCerrar;

	/************************************************************/
	/*********************** PROPIEDADES ************************/
	/************************************************************/

	@Override
	public Main getMain() {

		return this.main;
	}

	@Override
	public void setMain(Main mainApp) {
		this.main = mainApp;
	}

	public PolinomioInterpolante getPolinomio() {
		return polinomio;
	}

	public void setPolinomio(PolinomioInterpolante polinomio) {
		this.polinomio = polinomio;

		XYChart.Series<Double, Double> series = new XYChart.Series<Double, Double>();

		for (ParOrdenado par : this.polinomio.getSoporteAsociado()
				.getParesOrdenados()) {
			series.getData().add(
					new XYChart.Data<Double, Double>(par.getX(), par.getY()));
		}

		this.lineChartGrafico.getData().add(series);

	}

	public LineChart<Double, Double> getLineChartGrafico() {
		return lineChartGrafico;
	}

	public void setLineChartGrafico(LineChart<Double, Double> lineChartGrafico) {
		this.lineChartGrafico = lineChartGrafico;
	}

	public NumberAxis getEjeX() {
		return ejeX;
	}

	public void setEjeX(NumberAxis ejeX) {
		this.ejeX = ejeX;
	}

	public NumberAxis getEjeY() {
		return ejeY;
	}

	public void setEjeY(NumberAxis ejeY) {
		this.ejeY = ejeY;
	}

	public Button getBtnCerrar() {
		return btnCerrar;
	}

	public void setBtnCerrar(Button btnCerrar) {
		this.btnCerrar = btnCerrar;
	}

	public void setEscenario(Stage dialogStage) {
		this.escenario = dialogStage;
	}

	/************************************************************/
	/*********************** CONSTRUCTOR ************************/
	/************************************************************/

	/************************************************************/
	/******************** METODOS PUBLICOS **********************/
	/************************************************************/

	/************************************************************/
	/******************** METODOS PRIVADOS **********************/
	/************************************************************/

	/************************************************************/
	/********************* EVENT HANDLERS ***********************/
	/************************************************************/

	@FXML
	private void initialize() {
		ejeX.setAutoRanging(true);
		ejeY.setAutoRanging(true);
		lineChartGrafico.setVerticalZeroLineVisible(true);
		lineChartGrafico.setHorizontalZeroLineVisible(true);
		lineChartGrafico.setVerticalGridLinesVisible(true);
		lineChartGrafico.setHorizontalGridLinesVisible(true);
	}

	@FXML
	private void handleCerrarGrafico() {
		this.escenario.close();
	}

}
